
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>消息的压缩机制 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>消息的压缩机制 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Kafka引入消息压缩机制的主要目标是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">主要目标是减少网络带宽和存储空间的消耗，从而提高系统的整体性能。</div>
          </div>
          <div class="card-source">来源: Kafka 消息的压缩机制 —— 从源码的角度分析</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">请描述Kafka消息从生产者到消费者的完整压缩与解压流程。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 生产者压缩：生产者在发送消息前，将批次内的所有消息进行压缩。 2. Broker存储：Kafka Broker接收到压缩后的消息后，直接将其存储到磁盘，不进行解压。 3. 消费者解压：消费者从Broker拉取消息时，如果消息是压缩的，会自动进行解压缩以获得原始消息。</div>
          </div>
          <div class="card-source">来源: 1. 消息压缩的工作原理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Kafka支持哪些主流的消息压缩格式？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Kafka支持GZIP、Snappy、LZ4和Zstandard（Zstd）等多种压缩格式。</div>
          </div>
          <div class="card-source">来源: Kafka 消息的压缩机制 —— 从源码的角度分析</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在Kafka生产者中，哪个配置参数用于指定消息的压缩算法？默认值是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">使用 `compression.type` 参数来指定压缩算法。其默认值是 `none`，表示不进行压缩。</div>
          </div>
          <div class="card-source">来源: 2. Kafka 生产者端的压缩实现</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">对比GZIP和Snappy这两种压缩算法，它们在压缩率和性能方面有何不同，分别适合什么场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">GZIP的压缩率高，但性能较差，适合用于对压缩比要求较高的场景。Snappy的压缩速度快，压缩率适中，适合高吞吐量要求的场景。</div>
          </div>
          <div class="card-source">来源: 4. Kafka 消息压缩的性能影响</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">为什么说Kafka的批量消息处理（Batching）能够进一步提升压缩效率？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为生产者端会将多个消息合并为一个压缩包进行批量压缩，这可以进一步提高网络传输效率和存储利用率，同时还能降低分摊到每条消息上的压缩和解压缩开销。</div>
          </div>
          <div class="card-source">来源: 6. 批量消息的压缩</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">调优</div>
          <div class="card-question">除了选择压缩算法，还可以通过调整哪些关键参数来优化Kafka的压缩性能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">调优</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以调整`batch.size`（批量大小）和`buffer.memory`（压缩缓冲区大小）。例如，较大的批量可以提高压缩效率，但也可能导致延迟增加。</div>
          </div>
          <div class="card-source">来源: 7. 消息压缩的调优</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">根据文档描述，LZ4压缩算法适用于哪些应用场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">LZ4与Snappy类似，其特点是压缩速度快，因此适用于低延迟和高吞吐量的场景。</div>
          </div>
          <div class="card-source">来源: 4. Kafka 消息压缩的性能影响</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Kafka Broker在处理生产者发送的压缩消息时扮演什么角色？它会为了检查内容而解压消息吗？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Kafka Broker的角色是直接将接收到的压缩消息存储到磁盘中。它不会对消息进行解压，这保证了消息传输和存储的高效性。</div>
          </div>
          <div class="card-source">来源: 1. 消息压缩的工作原理</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
